package datastructures.graphcomponents;


public class Edge {

    private Node startNode;

    private Node endNode;

    private boolean directed;
    
    /**
     * Creates a new <code>Edge</code>. 
     * @param start      The <code>Node</code> where this <code>Edge</code> starts.
     * @param end        The <code>Node</code> where this <code>Edge</code> ends.
     * @param isDirected Is this <code>Edge</code> directed, can you only traverse it in one direction?
     * @throws IllegalArgumentException     If at least one of the parameters <code>start</code> or <code>end</code> are ==null.
     */
    public Edge(Node start,Node end,boolean isDirected){
        if (start == null || end == null) throw 
                new IllegalArgumentException("Argument == null!");
        
        endNode = end;
        startNode = start;
        this.directed = isDirected;
        
        assert startNode != null;
        assert endNode != null;
        
    }

    /**
     * Is this <code>Edge</code> directed?
     * @return <code>true</code>     If this <code>Edge</code> is directed, <code>false</code> otherwise.
     */
    public boolean isDirected () {
        return directed;
    }

    /**
     * Changes a directed <code>Edge</code> to an undirected and vice-versa.
     */
    public void changeDirected () {
        this.directed = !this.directed;
    }

    /**
     * Returns the <code>Node</code> where this <code>Edge</code> ends.
     * @return      The <code>Node</code> where this <code>Edge</code> ends.
     */
    public Node getEnd () {
        assert endNode != null;
        
        return endNode;
    }

    /**
     * Changes the <code>Node</code> at the end of this <code>Edge</code> to <code>val</code>.
     * @param val the <code>Node</code> where this <code>Edge</code> ends from now on.
     * @throws IllegalArgumentException if <code>val == null</code>.
     */
    public void setEnd (Node val) {
        if (val == null) throw new IllegalArgumentException();
        
        this.endNode = val;
    }

    /**
     * Returns the <code>Node</code> where this <code>Edge</code> starts.
     * @return      the <code>Node</code> where this <code>Edge</code> starts.
     */
    public Node getStart () {
        assert startNode != null;
        
        return startNode;
    }

    /**
     * Changes the <code>Node</code> at the beginning of this <code>Edge</code> to <code>val</code>.
     * @param val the <code>Node</code> where this <code>Edge</code> begins from now on.
     * @throws IllegalArgumentException if <code>val == null</code>.
     */
    public void setStart (Node val) {
        if (val == null) throw new IllegalArgumentException();
        
        this.startNode = val;
    }

    public Edge () {
    }

}

